package com.rn.ddd.interfaces.assembler;

import com.rn.ddd.domain.merchant.entity.Merchant;
import com.rn.ddd.infrastructure.base.AssemblerFactory;
import com.rn.ddd.interfaces.dto.MerchantDTO;

public class MerchantAssembler {

    private static final AssemblerFactory FACTORY = new AssemblerFactory();

    public static MerchantDTO toDTO(Merchant merchantDO) {
        if (merchantDO == null) {
            return null;
        }
        return FACTORY.convert((source, target) -> {
            target.setMerchantId(source.getId());
            target.setMerchantName(source.getMerchantName());
        }, merchantDO, MerchantDTO.class);
    }

    public static Merchant toEntity(MerchantDTO merchantDTO) {
        if (merchantDTO == null) {
            return null;
        }
        return FACTORY.convert((source, target) -> {
            target.setId(source.getMerchantId());
            target.setMerchantName(source.getMerchantName());
        }, merchantDTO, Merchant.class);
    }

}
